import Koa from 'koa'
import Router from 'koa-router'
import koaStatic from 'koa-static'
import bodyParser from 'koa-bodyparser'
import { allFiles, registryRouter } from './router/router.js'
import { registryTemplate } from './render/render.js'
import { sync } from './db/index.js'

const app = new Koa()
const router = new Router()

sync()

app.use(koaStatic(process.cwd() + '/statics'))

app.use(bodyParser())

let filesPath = allFiles('contorllers')
registryRouter(router, filesPath)

app.use(registryTemplate())


app.use(router.routes())

app.listen(8000)
console.log('http://localhost:8000/books')
